package medium;
/**
 * 重新组合word1，里面是否包含word2
 */

import java.util.HashMap;
import java.util.Set;

public class T5 {
    public static void main(String[] args) {
        String word1 = "abc";
        String word2 = "abd";
        System.out.println(new T5().validSubstringCount(word1, word2));
    }

    public long validSubstringCount(String word1, String word2) {
        HashMap<Character, Integer> map1 = new HashMap<>();
        HashMap<Character, Integer> map2 = new HashMap<>();
        for (int i = 0; i < word1.length(); i++) {
            if (!map1.containsKey(word1.charAt(i))) {
                map1.put(word1.charAt(i), 1);
            } else map1.put(word1.charAt(i),map1.get(word1.charAt(i))+1);
        }
        for (int i = 0; i < word2.length(); i++) {
            if (!map2.containsKey(word2.charAt(i))) {
                map2.put(word2.charAt(i), 1);
            } else map2.put(word2.charAt(i),map2.get(word2.charAt(i))+1);
        }
        Set<Character> set = map2.keySet();
        for (Character i:set){
           if (map1.get(i)==null || !(map1.get(i) - map2.get(i)>=0)){
               return 0;
           }
        }
        System.out.println(map1);
        System.out.println(map2);
        return 1;
    }
}
